﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using StackExchange.Redis;

namespace Redis读写分离.Common
{
    // 随机选择策略(默认)
    public class RandomSelectionStrategy : IReadServerSelectionStrategy
    {
        private readonly Random _random = new Random();

        public IDatabase SelectReadDatabase(IList<ConnectionMultiplexer> readConnections, int db = -1)
        {
            if (readConnections.Count == 0) return null;
            return readConnections[_random.Next(readConnections.Count)].GetDatabase(db);
        }
    }
}
